<!-- 手术室设备管理 -->
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: 'surgical/surgical' }">手术室管理</el-breadcrumb-item>
      <el-breadcrumb-item>手术室设备管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="surgeryInline" class="device-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="surgeryInline.deviceName" placeholder="输入设备名称"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-input size="small" v-model="surgeryInline.deptNo" placeholder="型号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        <el-button size="small" type="primary" icon="el-icon-plus" @click="deviceEdit()">添加</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="surgeryDevices" highlight-current-row v-loading="loading" border element-loading-text="数据加载中......" style="width:100%;">
      <el-table-column align="center" type="selection" width="60">
      </el-table-column>
      <el-table-column  align="center" prop="deviceName" label="设备名称" width="200">
      </el-table-column>
      <el-table-column   align="center" prop="deviceModel" label="型号" width="200">
      </el-table-column>
      <el-table-column   align="center" prop="status" label="状态" width="100">
      </el-table-column>
      <el-table-column  align="center" prop="bookingStatus" label="预约情况" width="100">
      </el-table-column>
      <el-table-column align="center"  prop="usageDate" label="使用日期" width="200">
      </el-table-column>
      <el-table-column  align="center" prop="maintenanceRecord" label="维护记录" width="200">
        <template slot-scope="scope">
          <div>{{scope.row.maintenanceRecord}}</div> 
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="300">
        <template slot-scope="scope">
          <el-button size="mini" @click="deviceEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="deleteDevice(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    <!-- 编辑界面 -->
    <el-dialog :title="title" :visible.sync="DeviceDeviceVisible" width="30%" @click="closeDialog">
      <el-form label-width="120px" :model="DeviceDevice" :rules="rules" ref="DeviceDevice">
        <el-form-item label="设备名称" prop="deviceName">
          <el-input size="small" v-model="DeviceDevice.deviceName" auto-complete="off" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="型号" prop="deviceModel">
          <el-input size="small" v-model="DeviceDevice.deviceModel" auto-complete="off" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-input size="small" v-model="DeviceDevice.status" auto-complete="off" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="预约情况" prop="bookingStatus">
          <el-input size="small" v-model="DeviceDevice.bookingStatus" auto-complete="off" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="使用日期" prop="usageDate">
          <el-input size="small" v-model="DeviceDevice.usageDate" auto-complete="off" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="维护记录" prop="maintenanceRecord">
          <el-input size="small" v-model="DeviceDevice.surgeryTim" auto-complete="off" placeholder="请输入"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeDialog">取消</el-button>
        <el-button size="small" type="primary" :loading="loading" class="title" @click="submitDevice('DeviceDevice')">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { surgeryDevice, deptSave, deptDelete } from '../../api/basisMG'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      DeviceDeviceVisible: false, //控制编辑页面显示与隐藏
      title: '添加',
      DeviceDevice: {
        deviceName: '', 
        deviceModel: '',
        status: '',
        bookingStatus: '', 
        usageDate: '', 
        maintenanceRecord: '' ,
        token: localStorage.getItem('logintoken')
      },
      // rules表单验证
      rules: {
        deviceName: [
          { required: true, message: '请输入设备名称', trigger: 'blur' }
        ],
        deviceModel: [{ required: true, message: '请输入型号', trigger: 'blur' }]
      },
      surgeryInline: {
        page: 1,
        limit: 10,
        varLable: '',
        varName: '',
        token: localStorage.getItem('logintoken')
      },
      // 删除部门
      seletedata: {
        ids: '',
        token: localStorage.getItem('logintoken')
      },
      userparm: [], //搜索权限
      surgeryDevices: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  created() {
    this.getdata(this.surgeryInline)
  },
  methods: {
    // 获取数据列表
    getdata(parameter) {
      this.loading = true
      // 模拟数据开始
      let res = {
        code: 0,
        msg: null,
        count: 50,
        data: [
        {  
        deviceName: '手术无影灯',  
        deviceModel: 'DL-1001',  
        status: '正常',  
        bookingStatus: '已预约',  
        usageDate: '2024-04-02',  
        usageDuration: '4小时',  
        maintenanceRecord: '上次维护：2024-03-25'  
      },  
      {  
        deviceName: '麻醉机',  
        deviceModel: 'MZ-5000',  
        status: '正常',  
        bookingStatus: '已预约',  
        usageDate: '2024-04-03',  
        usageDuration: '3小时',  
        maintenanceRecord: '上次维护：2024-04-01，下次维护计划：2024-06-01'  
      },  
      {  
        deviceName: '高频电刀',  
        deviceModel: 'GD-8000',  
        status: '正常',  
        bookingStatus: '未预约',  
        usageDate: '-',  
        usageDuration: '-',  
        maintenanceRecord: '上次维护：2024-03-15'  
      },  
      {  
        deviceName: '心电监护仪',  
        deviceModel: 'ECG-600',  
        status: '正常',  
        bookingStatus: '已预约',  
        usageDate: '2024-04-05',  
        usageDuration: '6小时',  
        maintenanceRecord: '无'  
      },  
      {  
        deviceName: '呼吸机',  
        deviceModel: 'RES-9000',  
        status: '正常',  
        bookingStatus: '已预约',  
        usageDate: '2024-04-07',  
        usageDuration: '5小时',  
        maintenanceRecord: '上次维护：2024-02-28'  
      },  
      {  
        deviceName: '输液泵',  
        deviceModel: 'IVP-400',  
        status: '正常',  
        bookingStatus: '未预约',  
        usageDate: '-',  
        usageDuration: '-',  
        maintenanceRecord: '上次维护：2024-01-10，下次维护计划：2024-05-10'  
      },  
      {  
        deviceName: '显微镜',  
        deviceModel: 'OPT-2000',  
        status: '正常',  
        bookingStatus: '已预约',  
        usageDate: '2024-04-09',  
        usageDuration: '4小时',  
        maintenanceRecord: '上次维护：2023-12-30'  
      },  
      {  
        deviceName: '腹腔镜',  
        deviceModel: 'LAP-7000',  
        status: '维护中',  
        bookingStatus: '未预约',  
        usageDate: '-',  
        usageDuration: '-',  
        maintenanceRecord: '正在维护：2024-04-01至2024-04-04'  
      },  
      {  
        deviceName: 'C型臂X光机',  
        deviceModel: 'CARM-550',  
        status: '正常',  
        bookingStatus: '已预约',  
        usageDate: '2024-04-10',  
        usageDuration: '3小时',  
        maintenanceRecord: '上次维护：2024-04-08'  
      },  
      {  
        deviceName: '手术床',  
        deviceModel: 'OPB-120',  
        status: '正常',  
        bookingStatus: '未预约',  
        usageDate: '-',  
        usageDuration: '-',  
        maintenanceRecord: '无'  
      }  
        ]
      }
      this.loading = false
      this.surgeryDevices = res.data
      this.pageparm.currentPage = this.surgeryInline.page
      this.pageparm.pageSize = this.surgeryInline.limit
      this.pageparm.total = res.count
      // 测试环境  模拟数据结束  

      /***
       *  正式环境环境 调用接口
       */
       surgeryDevice(parameter)
        .then(res => {
          this.loading = false
          if (res.success == false) {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {
            this.surgeryDevices = res.data
            // 分页赋值
            this.pageparm.currentPage = this.surgeryInline.page
            this.pageparm.pageSize = this.surgeryInline.limit
            this.pageparm.total = res.count
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('加载失败，请稍后再试！')
        })
    },
    // 分页插件事件
    callFather(parm) {
      this.surgeryInline.page = parm.currentPage
      this.surgeryInline.limit = parm.pageSize
      this.getdata(this.surgeryInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.surgeryInline)
    },
    //显示编辑界面
    deviceEdit: function(index, row) {
      this.DeviceDeviceVisible = true
      if (row != undefined && row != 'undefined') {
        this.title = '修改'
        this.DeviceDevice.deviceName = row.deviceName
        this.DeviceDevice.deviceModel = row.deviceModel
        this.DeviceDevice.status = row.status
        this.DeviceDevice.bookingStatus = row.bookingStatus
        this.DeviceDevice.usageDate = row.usageDate
        this.DeviceDevice.maintenanceRecord = row.maintenanceRecord
      } else {
        this.title = '添加'
        this.DeviceDevice.deviceName = ''
        this.DeviceDevice.deviceModel = ''
        this.DeviceDevice.status = ''
        this.DeviceDevice.bookingStatus=''
        this.DeviceDevice.usageDate =''
        this.DeviceDevice.maintenanceRecord=''
      }
    },
    // 编辑、增加页面保存方法
    submitDevice(editData) {
      this.$refs[editData].validate(valid => {
        if (valid) {
          deptSave(this.DeviceDevice)
            .then(res => {
              this.DeviceDeviceVisible = false
              this.loading = false
              if (res.success) {
                this.getdata(this.surgeryInline)
                this.$message({
                  type: 'success',
                  message: '手术室设备保存成功！'
                })
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.DeviceDeviceVisible = false
              this.loading = false
              this.$message.error('手术室设备保存失败，请稍后再试！')
            })
        } else {
          return false
        }
      })
    },
    // 删除手术室设备
    deleteDevice(index, row) {
      this.$confirm(`确定要删除手术室设备吗?`, '删除手术室设备', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deptDelete(row.deviceName)
            .then(res => {
              if (res.success) {
                this.$message({
                  type: 'success',
                  message: '手术室设备已删除!'
                })
                this.getdata(this.surgeryInline)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error('手术室设备删除失败，请稍后再试！')
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 关闭编辑、增加弹出框
    closeDialog() {
      this.DeviceDeviceVisible = false
    }
  }
}
</script>

<style scoped>
.device-search {
  margin-top: 20px;
}
</style>

 
 